import requests


class IRHMApi:

    # 封装登录接口
    @classmethod
    def ihrm_login_api(cls, login_body):
        login_url = "http://ihrm2-test.itheima.net/api/sys/login"
        login_header = {"Content-Type": "application/json"}
        login_resp = requests.post(url=login_url, headers=login_header, json=login_body)
        return login_resp

    # 封装员工添加接口
    @classmethod
    def ihrm_add_emp(cls, token, add_emp_body):
        add_emp_url = "http://ihrm2-test.itheima.net/api/sys/user"
        add_emp_header = {"Content-Type": "application/json", "Authorization": token}
        add_emp_resp = requests.post(url=add_emp_url, headers=add_emp_header, json=add_emp_body)
        return add_emp_resp

    # 封装员工查询接口
    @classmethod
    def ihrm_query_emp(cls, emp_id, token):
        query_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        query_emp_header = {"Authorization": token}
        query_emp_resp = requests.get(url=query_emp_url, headers=query_emp_header)
        return query_emp_resp

    # 封装员工修改接口
    @classmethod
    def ihrm_modify_emp(cls, emp_id, token, modify_emp_body):
        modify_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        modify_emp_header = {"Content-Type": "application/json",
                             "Authorization": token}
        modify_emp_resp = requests.put(url=modify_emp_url, headers=modify_emp_header, json=modify_emp_body)
        return modify_emp_resp

    # 封装员工删除接口
    @classmethod
    def ihrm_del_emp(cls, emp_id, token):
        del_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        del_emp_header = {"Authorization": token}
        del_emp_resp = requests.delete(url=del_emp_url, headers=del_emp_header)
        return del_emp_resp


if __name__ == '__main__':
    token = '8a79264c-89f6-4a49-b975-8c1f11941fb9'
    body = {
        "username": "小猪佩奇",
        "mobile": "15912998845",
        "workNumber": "22"
    }
    resp = IRHMApi.ihrm_add_emp(token,body)
    print("resp=",resp.json())
